package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

//    查询所有员工;使用pagehelper就是分页查询,会自动在sql语句后添加limit故拿剪子
//    @Select("Select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id order by update_time desc")
    List<Emp> list(EmpQueryParam queryParam);


    /**
     * 新增员工
     * @param emp
     */
//    需要返回新增员工的id值,且赋值给emp_List表的员工id
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into emp (username, name, gender, phone, job, salary, image," +
            " entry_date, dept_id, create_time, update_time) " +
            "values (#{username}, #{name}, #{gender}, #{phone},#{job},#{salary},#{image}," +
            "#{entryDate},#{deptId}, #{createTime}, #{updateTime})")
    void insert(Emp emp);

    /**
     * 根据Id删除员工
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 员工信息回显
     * @param id
     * @return
     */
    @Select("select * from emp where id = #{id}")
    Emp getById(Integer id);

    /**
     * 动态SQL修改员工信息
     * @param emp
     */
    void updateById(Emp emp);

    /**
     * 获取员工性别数据展示,饼状图
     * @return
     */
    List<Map<String, Object>> empGenderData();

    /**
     * 获取员工职位数据展示,柱状图
     * @return
     */
    List<Map<String, Object>> empJobData();

    /**
     * 查询所有员工
     * @param
     * @return
     */
    @Select("select * from emp")
    List<Emp> selectAll();

    /**
     * 员工登录查询信息
     * @param emp
     * @return
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp login(Emp emp);

    /**
     * 修改员工登录密码
     * @param id
     * @param newpassword
     */
    @Update("update emp set password = #{newpassword} where id = #{id}")
    void updatePassword(Integer id, String newpassword);
}
